<template>
    <view class="content">
        <u-search  @click="go" placeholder="搜索" actionText="取消" @change="change" @custom="custom"   v-model="keyword"></u-search>

         <view class="search-box">
            <view @click="router(item.title)" class="search-box-item" v-for="(item,index) in list" :key="index" >
                <u-icon name="search"></u-icon>
                <view class="search-box-item-text" v-if="keyword == ''"> {{item.title}}</view>
				<view class="search-box-item-text" v-else> 
				<span v-for="(items,index) in item.title">
					<span v-if="items != ''">{{items}}</span>
					<span style="color: red;" v-else>{{keyword}}</span>
				</span>
					
				</view>
            </view>
        </view>

    </view>
</template>
<script>
export default {
    name: 'index',
    components: {

    },
    data() {
        return {
            keyword:'',
			show:false,
			list:[],
			total:0,
			list:[],
			totals:0,
			page:1,
			pages:1
        }
    },
	onLoad(e) {
		this.getlist()
	},
    methods: {
		getlist(){
			var that = this
			this.$.ajax(1,'POST','/index/getserchhistory',{
				page:this.page
			},(res)=>{
				if(this.pages == 1){
					that.list = []
				}
				that.list = [...res.data.list,...that.list]
				that.total = res.data.total
			})
		},
		change(e){
			console.log(e)
			if(!e){
				this.list = []
				this.getlist()
			}else{
				var that = this
				this.$.ajax(1,'POST','/index/getgoodsserch',{
					keyword:this.keyword,
					page:this.pages
				},(res)=>{
					// if(res.data.list.length > 0){
						if(this.pages == 1){
							that.list = []
						}
						that.list = [...res.data.list,...that.list]
						that.totals = res.data.total
					// }
				})
			}
			
		},
        custom(){
            uni.navigateBack()
        },
        go(){
			
        },
        router(e){
            uni.navigateTo({url: '/pages/index/searchList?keyword='+e})
        }
    },
    created() {

    },
    mounted() {

    },
}
</script>
<style lang="scss" scoped>

.content{
    position: absolute;
    width: 100%;
    padding:20rpx 20rpx;
    height: 100%;
  font-size: 28rpx;
    background-color: #fff;
  .search-box-item{
    padding: 30rpx 0;
    border-bottom: 1rpx solid #F4F4F4;
    display: flex;
    align-items: center;
    gap: 20rpx;
  }
}
</style>

